package com.czz.manage.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @ClassName: DateUtil
 * @Author Czz
 * @Date 2020/3/12
 * @Time 12:16
 **/
public class DateUtil {
    public static List<String> findDates(String dStart, String dEnd) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        List<String> dateList=null;
        try {
            Calendar cStart = Calendar.getInstance();
            cStart.setTime(sdf.parse(dStart));
            dateList = new ArrayList<String>();
            //别忘了，把起始日期加上
            dateList.add(dStart);
            // 此日期是否在指定日期之后
            while (sdf.parse(dEnd).after(cStart.getTime())) {
                // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
                cStart.add(Calendar.DAY_OF_MONTH, 1);
                dateList.add(sdf.format(cStart.getTime()));
            }
        }catch(Exception e) {
            e.printStackTrace();
        }
        return dateList;
    }
}
